package com.xigua.xcar.phonenumlist;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.xigua.xcar.R;
import com.xigua.xcar.base.BaseActivity;
import com.xigua.xcar.constant.BrandConstants;
import com.xigua.xcar.constant.Constants;
import com.xigua.xcar.data.CommonListData;
import com.xigua.xcar.util.CommonListUtil;
import com.xigua.xcar.widgets.CommonList.CommonListAdapter;

public class PhoneNumListActivity extends BaseActivity {
	private static final String tag = "PhoneNumListActivity";
	private ListView mListView = null;
	private ArrayList<CommonListData> mArray = null;
	private CommonListAdapter mAdapter = null;

	@Override
	protected void finalize() throws Throwable {
		// 注销的注意事项
		super.finalize();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.i(tag, "onCreate");
		super.onCreate(savedInstanceState);
		setView(R.layout.phonenum);
		setTopBarTitle("搜索");
		setTitleBar(R.drawable.title_button, "返回", 0, "");
		mListView = (ListView) findViewById(R.id.listview_phonenum_main);
		mArray = new ArrayList<CommonListData>();
		mAdapter = new CommonListAdapter(this);
		mAdapter.setItemClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				CommonListData data = (CommonListData) v.getTag();
				CommonListUtil.getPopupWindow(PhoneNumListActivity.this, v,
						data.getmPhoneNum(), data.getmShopName());
			}
		});
		int index;
		Intent intent = getIntent();
		index = intent.getIntExtra(Constants.COMMON_FROMWHERE, 0);
		initData(index);
		mAdapter.setData(mArray);
		mListView.setAdapter(mAdapter);
	}

	private void initData(int index) {
		for (int i = 0; i < BrandConstants.SHOPS[index].length; i = i + 2) {
			CommonListData data = new CommonListData();
			data.setmResId(R.drawable.icon_rightarray);
			data.setmShopName(BrandConstants.SHOPS[index][i]);
			data.setmPhoneNum(BrandConstants.SHOPS[index][i + 1]);
			mArray.add(data);
		}
	}

	@Override
	protected void handleTitleBarEvent(int buttonId) {
		switch (buttonId) {
		case Constants.LEFTBUTTONID: {
			this.finish();
			break;
		}
		case Constants.RIGHTBUTTONID: {
			break;
		}
		}
	}
}
